package com.king.eventbusdemo;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.king.eventbusdemo.entity.EventBusBean;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends AppCompatActivity {


    TextView tv_content;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        EventBus.getDefault().register(MainActivity.this);
        initView();
    }

    private void initView() {
        tv_content = findViewById(R.id.tv_content);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void eventBuseMessage(EventBusBean eventBusBean){
        tv_content.setText(eventBusBean.name+"--"+eventBusBean.pwd);
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(MainActivity.this);
    }

    public void voidset(View view) {
        startActivity(new Intent(MainActivity.this,SamePageActivity.class));
    }

    public void goMessage(View view) {
        startActivity(new Intent(MainActivity.this,OrtherCallResult.class));
    }
    public void goToMessage(View view) {
        EventBus.getDefault().postSticky(new EventBusBean("111--","2222"));
        startActivity(new Intent(MainActivity.this,JSMessageActivity.class));
    }
}
